# -*- coding: utf-8 -*-
import re
import scrapy
from ..items import GirlItem

class XiaohuaSpider(scrapy.Spider):
    name = "xiaohua"
    allowed_domains = ["www.jianshu.com"]
    start_urls = ['https://www.jianshu.com/c/V2CqjW?order_by=added_at&page={}'.format(i) for i in range(1,13)]
    def parse(self, response):
        #取到每一页的列表
        url = response.xpath('//div[@class="content"]/a/@href').extract()
        for i in url:
            yield  scrapy.Request('https://www.jianshu.com' + i ,callback = self.title)
    def title(self,response):
        name = response.xpath('//div[@class="article"]/h1[@class="title"]/text()').extract()[0]
        html = response.url
        item = GirlItem()
        item['name'] = name
        item['url'] = html
        yield item


